package com.ma.reportForm;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.ma.R;

import java.util.ArrayList;
import java.util.List;

import base.BaseActivity;
import lomasky.xui.BaseViewHolderForListView;
import lomasky.xui.CommonAdapter;
import lomasky.xui.NoScrollGridView;
import lomasky.xui.RoundProgressBar;

public class CollectFeesAnalzeActivity extends BaseActivity {

    private RoundProgressBar mRoundProgressBar;
    private NoScrollGridView mIconGroup1;
    private NoScrollGridView mIconGroup2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_collect_fees_analze);
        initView();
        initView1();



    }

    private void initView1() {


        List<DataBean> list = new ArrayList<>();
        list.add(new DataBean("本月应收", "60.00"));
        list.add(new DataBean("本月实收", "50.00"));
        list.add(new DataBean("本月欠收", "10.00"));
        list.add(new DataBean("本月收款", "50.00"));
        list.add(new DataBean("总欠费", "160.00"));

        list.add(new DataBean("", ""));
        list.add(new DataBean("", ""));
        list.add(new DataBean("", ""));


        CommonAdapter<DataBean> adapter = new CommonAdapter<DataBean>(this, list, R.layout.collect_fees_bottom_item1) {
            @Override
            public void convert(BaseViewHolderForListView helper, DataBean item,int position) {
                if (TextUtils.isEmpty(item.text)) {
                    helper.getTextView(R.id.money).setBackgroundResource(R.drawable.transparent);
                    helper.setText(R.id.money, "");
                    helper.setText(R.id.text, "");



                } else {

                    helper.setText(R.id.text, item.text);
                    helper.setText(R.id.money, item.money);
                    if (item.isCheck){
                        helper.getTextView(R.id.money).setTextColor(getResources().getColor(R.color.white));
                        helper.getTextView(R.id.text).setTextColor(getResources().getColor(R.color.colorPrimary));
                        helper.getTextView(R.id.money).setBackgroundResource(R.drawable.bound_bg2);

                    }else {
                        helper.getTextView(R.id.money).setTextColor(getResources().getColor(R.color.colorPrimary));
                        helper.getTextView(R.id.text).setTextColor(getResources().getColor(R.color.dark));
                        helper.getTextView(R.id.money).setBackgroundResource(R.drawable.bound_bg1);
                    }
                }


            }
        };

        mIconGroup1.setOnItemClickListener((adapterView, view, position, l) -> {

            for (int i = 0; i < list.size(); i++) {

                list.get(i).setCheck(i==position);


            }
            adapter.setList(list);
            adapter.notifyDataSetChanged();

            if (position == 0) {
                List<DataBean> dataBeanList = new ArrayList<>();
                dataBeanList.add(new DataBean("物业服务费", "40.00万"));
                dataBeanList.add(new DataBean("水电费", "5.00万"));
                dataBeanList.add(new DataBean("公摊费", "6.00万"));
                dataBeanList.add(new DataBean("租金", "7.00万"));
                dataBeanList.add(new DataBean("其他", "2.00万"));

                dataBeanList.add(new DataBean("", ""));
                dataBeanList.add(new DataBean("", ""));
                dataBeanList.add(new DataBean("", ""));
                initView2(dataBeanList);
            }else if (position==1){

                List<DataBean> dataBeanList = new ArrayList<>();
                dataBeanList.add(new DataBean("物业服务费", "40.00万"));
                dataBeanList.add(new DataBean("水电费", "5.00万"));
                dataBeanList.add(new DataBean("公摊费", "6.00万"));
                dataBeanList.add(new DataBean("租金", "7.00万"));
                dataBeanList.add(new DataBean("押金", "1.00万"));

                dataBeanList.add(new DataBean("经营收入", "4.50万"));
                dataBeanList.add(new DataBean("其他", "3.00万"));
                dataBeanList.add(new DataBean("", ""));
                initView2(dataBeanList);


            }
            else if (position==2){

                List<DataBean> dataBeanList = new ArrayList<>();
                dataBeanList.add(new DataBean("物业服务费", "40.00万"));
                dataBeanList.add(new DataBean("水电费", "5.00万"));
                dataBeanList.add(new DataBean("公摊费", "6.00万"));
                dataBeanList.add(new DataBean("租金", "7.00万"));
                dataBeanList.add(new DataBean("其他", "2.00万"));

                dataBeanList.add(new DataBean("", ""));
                dataBeanList.add(new DataBean("", ""));
                dataBeanList.add(new DataBean("", ""));
                initView2(dataBeanList);


            }
            else if (position==3){




            }





        });


        mIconGroup1.setAdapter(adapter);

    }

    private void initView() {
        mRoundProgressBar = (RoundProgressBar) findViewById(R.id.roundProgressBar);
        mRoundProgressBar.setProgress(45);
        mIconGroup1 = (NoScrollGridView) findViewById(R.id.icon_group1);
        mIconGroup2 = (NoScrollGridView) findViewById(R.id.icon_group2);
    }

    private void initView2(List<DataBean> list) {



        CommonAdapter<DataBean> iconTextCommonAdapter = new CommonAdapter<DataBean>(this, list, R.layout.collect_fees_bottom_item2) {
            @Override
            public void convert(BaseViewHolderForListView helper, DataBean item,int position) {
                if (TextUtils.isEmpty(item.text)) {
                    helper.getTextView(R.id.money).setBackgroundResource(R.drawable.transparent);
                    helper.setText(R.id.money, "");
                    helper.setText(R.id.text, "");



                } else {

                    helper.setText(R.id.text, item.text);
                    helper.setText(R.id.money, item.money);
                }


            }
        };

        mIconGroup2.setAdapter(iconTextCommonAdapter);
        mIconGroup2.setOnItemClickListener((adapterView, view, i, l) -> {





        });


    }

    public void showDialog(View view) {

        new ChooseProjectDialog(this).show();
    }

    class DataBean {
        public String text;
        public String money;
        public boolean isCheck;

        public DataBean(String text1, String text2) {
            this.text = text1;
            this.money = text2;
        }

        public boolean isCheck() {
            return isCheck;
        }

        public void setCheck(boolean check) {
            isCheck = check;
        }

        public String getText() {
            return text;
        }

        public void setText(String text) {
            this.text = text;
        }
    }

}
